-module(menu).
-include_lib("nitrogen/include/wf.inc").
-compile(export_all).

render() ->
    A = [#p{}],
    B_content = case wf:session(connected) of
	    true -> [
		     #p{},
		     #link{text = "Apprendre", url = "/web/learn"} , #br{},
		     " -> ", #br{},

		     #link{text = "Coder", url = "/web/code"} ,#br{},
		     " -> ", #br{},

		     #link{text = "Partager", url = "/web/share"},
		     
		     #p{},
		     element_login:render(logout)
		    ];

	    false -> [
		      #p{},
		      element_login:render(login), #br{},
		      #link{text = "S'enregistrer", actions=helper:act(?MODULE, update_elogins)}%postback=update_elogins}
		     ]
	end,
    B = [#rounded_panel { id=elogins, color=gray, body=B_content }], 
    wf:render(A ++ B).

event(update_elogins) ->
    wf:update(elogins, #rounded_panel {color=gray, body = [ element_register:render(), #br{}, #link{text="Back", url="/web/index"}] }).

exec(Fun, Arg) -> %Required to handle web_code module
    Fun(Arg).
